#-*-coding: utf-8 -*-

import os
import sys

import win32api
import win32gui
from win32con import WM_INPUTLANGCHANGEREQUEST

def _is_equal(v1, v2):
    ## ignore case

    if len(v1) != len(v2):
        return 0

    s1 = v1.lower()
    s2 = v2.lower()

    if s1 == s2:
        return True
    else:
        return False

def _is_equal2(v1, v2):
    ## ignore case

    if len(v1) != len(v1):
        return 0

    s1 = "".join(chr(i) for i in v1).lower()
    s2 = v2.lower()

    if s1 == s2:
        return 1
    else:
        return 0

def _xputs(ch):
    print(ch, end="")
    sys.stdout.flush()

def change_language(lang="EN"):
    LANG = {
        "ZH": 0x0804,
        "EN": 0x0409
    }
    hwnd = win32gui.GetForegroundWindow()
    language = LANG[lang]
    result = win32api.SendMessage(
        hwnd,
        WM_INPUTLANGCHANGEREQUEST,
        0,
        language
    )
    if not result:
        return True

def env_init(lang="EN", cls=True, curs=True):
    if curs:
        os.system('echo -e "\033[?25h" 1>NUL')
    else:
        os.system('echo -e "\033[?25l"')

    if cls:
        os.system('cls')

    change_language(lang)

if __name__ == "__main__":
    env_init("EN", False)
